import 'package:base_flutter/base_flutter.dart' as b;
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cupertino_date_picker_fork/flutter_cupertino_date_picker_fork.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/a_elder/page/elder_content_page.dart';
import 'package:ls_work/mvp/svp_progress.dart';
import 'package:ls_work/net/HttpUtil.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/ui/select_old_page.dart';
import 'package:ls_work/util/app_navigator.dart';
import 'package:ls_work/util/toast.dart';
import 'package:ls_work/widgets/base_dialog.dart';
import 'package:ls_work/widgets/load_image.dart';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:oktoast/oktoast.dart';

import '../../util/flat_button.dart';



class HealthRegistPage extends StatefulWidget {
  final ElderInfo? info;

  HealthRegistPage({this.info});

  @override
  _HealthRegistPageState createState() => _HealthRegistPageState();
}

class _HealthRegistPageState extends State<HealthRegistPage> {
  String time =
      DateUtil.formatDate(DateTime.now(), format: DateFormats.y_mo_d_h_m);
  TextEditingController textFieldEditer = TextEditingController();
  TextEditingController dialogController = TextEditingController();
  FocusNode dialogFocusNode = FocusNode();
  FocusNode textFocusNode = FocusNode();

  DateTime _selectedDate = DateTime.now(); //当前选中的日期
  String elderName = '';
  ElderInfo? elderInfo;

  String heightValue = '';
  String weightValue = '';
  String highValue = '';
  String lowValue = '';
  String oxygenValue = '';
  String pulseRateValue = '';
  String heartValue = '';
  String temperatureValue = '';
  String bowelsNumValue = '';
  String breatheValue = '';
  String bloodSugarBeforeBreakfastValue = '';
  String bloodSugarLastBreakfastValue = '';
  String bloodSugarBeforeLunchValue = '';
  String bloodSugarLastLunchValue = '';
  String bloodSugarBeforeDinnerValue = '';
  String bloodSugarLastDinnerValue = '';
  String bloodSugarBeforeSleepValue = '';
  String bloodSugarLastOtherValue = '';


  ///获取数据
  _send() {
    FocusScope.of(context).unfocus();
    if (elderInfo == null) {
      Toast.show('请选择老人');
      return;
    }
    Map<String, dynamic> map = {
      'customerId': elderInfo?.id,
      'collectionTime': time + ':00',
      'sourceId': 3
    };
    if (heightValue.isNotEmpty) map['height'] = heightValue;
    if (weightValue.isNotEmpty) map['weight'] = weightValue;
    if (highValue.isNotEmpty) map['high'] = highValue;
    if (lowValue.isNotEmpty) map['low'] = lowValue;
    if (oxygenValue.isNotEmpty) map['oxygen'] = oxygenValue;
    if (pulseRateValue.isNotEmpty) map['pulseRate'] = pulseRateValue;
    if (heartValue.isNotEmpty) map['heart'] = heartValue;
    if (temperatureValue.isNotEmpty) map['temperature'] = temperatureValue;
    if (bowelsNumValue.isNotEmpty) map['bowelsNum'] = bowelsNumValue;
    if (breatheValue.isNotEmpty) map['breathe'] = breatheValue;
    if (bloodSugarBeforeBreakfastValue.isNotEmpty)
      map['bloodSugarBeforeBreakfast'] = bloodSugarBeforeBreakfastValue;
    if (bloodSugarLastBreakfastValue.isNotEmpty)
      map['bloodSugarLastBreakfast'] = bloodSugarLastBreakfastValue;
    if (bloodSugarBeforeLunchValue.isNotEmpty)
      map['bloodSugarBeforeLunch'] = bloodSugarBeforeLunchValue;
    if (bloodSugarLastLunchValue.isNotEmpty)
      map['bloodSugarLastLunch'] = bloodSugarLastLunchValue;
    if (bloodSugarBeforeDinnerValue.isNotEmpty)
      map['bloodSugarBeforeDinner'] = bloodSugarBeforeDinnerValue;
    if (bloodSugarLastDinnerValue.isNotEmpty)
      map['bloodSugarLastDinner'] = bloodSugarLastDinnerValue;
    if (bloodSugarBeforeSleepValue.isNotEmpty)
      map['bloodSugarBeforeSleep'] = bloodSugarBeforeSleepValue;
    if (bloodSugarLastOtherValue.isNotEmpty)
      map['bloodSugarLastOther'] = bloodSugarLastOtherValue;
    if (textFieldEditer.text.isNotEmpty) map['remark'] = textFieldEditer.text;

    SVProgressHUD page = SVProgressHUD(context);
    page.showProgress();
    HttpUtil.instance
        .getDio()
        .post('${HttpApi.createBean}?${requestParams(map)}')
        .then((r) {
      ///
      page.closeProgress();
      if (r.statusCode == 200) {
        Map<String, dynamic> map = json.decode(r.toString());

        if (map["code"].toString() == "0") {
          Toast.show(map["msg"]);
          // Navigator.pop(context);
          _clearInfo();
          _clearElder();
        } else {
          Toast.show(map["msg"]);
        }
      } else {
        Toast.show(r.statusCode.toString());
      }
    }).catchError((e) {
      page.closeProgress();
      print(e.toString());
      Toast.show(getErrorMessage(e));
    });
  }

  ///重置
  _reset() {
    Navigator.pop(context);
    _clearInfo();
  }

  void _clearInfo(){
    setState(() {
      heightValue = '';
      weightValue = '';
      highValue = '';
      lowValue = '';
      oxygenValue = '';
      pulseRateValue = '';
      heartValue = '';
      temperatureValue = '';
      bowelsNumValue = '';
      breatheValue = '';
      bloodSugarBeforeBreakfastValue = '';
      bloodSugarLastBreakfastValue = '';
      bloodSugarBeforeLunchValue = '';
      bloodSugarLastLunchValue = '';
      bloodSugarBeforeDinnerValue = '';
      bloodSugarLastDinnerValue = '';
      bloodSugarBeforeSleepValue = '';
      bloodSugarLastOtherValue = '';
      textFieldEditer.text = '';
    });
  }

  void _clearElder(){
    setState(() {
      elderName = '';
      elderInfo = null;
    });
  }

  @override
  Widget build(BuildContext context) {
    // if(textFocusNode.hasFocus){
    //   textFocusNode.unfocus();
    // }
    return SingleChildScrollView(
        child: Container(
      width: ScreenUtil.getScreenW(context),
      child: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            topButtonItem(
                elderTitle: '老人姓名',
                elderContent: elderName,
                timeTitle: '采集时间',
                timeContent: time),
            Row(
              children: <Widget>[
                cellItem('身高cm', heightValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(heightValue)??0,
                    callBack: (value) {
                      setState(() {
                        heightValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (heightValue.isEmpty) {
                      heightValue = '160';
                    } else {
                      num temp = NumUtil.getNumByValueStr(heightValue)??0;
                      temp--;
                      heightValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (heightValue.isEmpty) {
                      heightValue = '160';
                    } else {
                      num temp = NumUtil.getNumByValueStr(heightValue)??0;
                      temp++;
                      heightValue = temp.toString();
                    }
                  });
                }),
                cellItem('体重(kg)', weightValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(weightValue)??0,
                    callBack: (value) {
                      setState(() {
                        weightValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (weightValue.isEmpty) {
                      weightValue = '50';
                    } else {
                      num temp = NumUtil.getNumByValueStr(weightValue)??0;
                      temp--;
                      weightValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (weightValue.isEmpty) {
                      weightValue = '50';
                    } else {
                      num temp = NumUtil.getNumByValueStr(weightValue)??0;
                      temp++;
                      weightValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('低压(mmHg)', lowValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(lowValue)??0,
                    callBack: (value) {
                      setState(() {
                        lowValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (lowValue.isEmpty) {
                      lowValue = '75';
                    } else {
                      num temp = NumUtil.getNumByValueStr(lowValue)??0;
                      temp--;
                      lowValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (lowValue.isEmpty) {
                      lowValue = '75';
                    } else {
                      num temp = NumUtil.getNumByValueStr(lowValue)??0;
                      temp++;
                      lowValue = temp.toString();
                    }
                  });
                }),
                cellItem('高压(mmHg)', highValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(highValue)??0,
                    callBack: (value) {
                      setState(() {
                        highValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (highValue.isEmpty) {
                      highValue = '115';
                    } else {
                      num temp = NumUtil.getNumByValueStr(highValue)??0;
                      temp--;
                      highValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (highValue.isEmpty) {
                      highValue = '115';
                    } else {
                      num temp = NumUtil.getNumByValueStr(highValue)??0;
                      temp++;
                      highValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('血氧(%)', oxygenValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(oxygenValue)??0,
                    callBack: (value) {
                      setState(() {
                        oxygenValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (oxygenValue.isEmpty) {
                      oxygenValue = '95';
                    } else {
                      num temp = NumUtil.getNumByValueStr(oxygenValue)??0;
                      temp--;
                      oxygenValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (oxygenValue.isEmpty) {
                      oxygenValue = '95';
                    } else {
                      num temp = NumUtil.getNumByValueStr(oxygenValue)??0;
                      temp++;
                      oxygenValue = temp.toString();
                    }
                  });
                }),
                cellItem('脉率(bpm)', pulseRateValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(pulseRateValue)??0,
                    callBack: (value) {
                      setState(() {
                        pulseRateValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (pulseRateValue.isEmpty) {
                      pulseRateValue = '70';
                    } else {
                      num temp = NumUtil.getNumByValueStr(pulseRateValue)??0;
                      temp--;
                      pulseRateValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (pulseRateValue.isEmpty) {
                      pulseRateValue = '70';
                    } else {
                      num temp = NumUtil.getNumByValueStr(pulseRateValue)??0;
                      temp++;
                      pulseRateValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('心率(bpm)', heartValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(heartValue)??0,
                    callBack: (value) {
                      setState(() {
                        heartValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (heartValue.isEmpty) {
                      heartValue = '70';
                    } else {
                      num temp = NumUtil.getNumByValueStr(heartValue)??0;
                      temp--;
                      heartValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (heartValue.isEmpty) {
                      heartValue = '70';
                    } else {
                      num temp = NumUtil.getNumByValueStr(heartValue)??0;
                      temp++;
                      heartValue = temp.toString();
                    }
                  });
                }),
                cellItem('体温(℃)', temperatureValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(temperatureValue)??0,
                    callBack: (value) {
                      setState(() {
                        temperatureValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (temperatureValue.isEmpty) {
                      temperatureValue = '36';
                    } else {
                      num temp = NumUtil.getNumByValueStr(temperatureValue)??0;
                      temp--;
                      temperatureValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (temperatureValue.isEmpty) {
                      temperatureValue = '36';
                    } else {
                      num temp = NumUtil.getNumByValueStr(temperatureValue)??0;
                      temp++;
                      temperatureValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('大便(次)', bowelsNumValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(bowelsNumValue)??0,
                    callBack: (value) {
                      setState(() {
                        bowelsNumValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bowelsNumValue.isEmpty) {
                      bowelsNumValue = '1';
                    } else {
                      num temp = NumUtil.getNumByValueStr(bowelsNumValue)??0;
                      temp--;
                      bowelsNumValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bowelsNumValue.isEmpty) {
                      bowelsNumValue = '1';
                    } else {
                      num temp = NumUtil.getNumByValueStr(bowelsNumValue)??0;
                      temp++;
                      bowelsNumValue = temp.toString();
                    }
                  });
                }),
                cellItem('呼吸(次)', breatheValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(breatheValue)??0,
                    callBack: (value) {
                      setState(() {
                        breatheValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (breatheValue.isEmpty) {
                      breatheValue = '20';
                    } else {
                      num temp = NumUtil.getNumByValueStr(breatheValue)??0;
                      temp--;
                      breatheValue = temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (breatheValue.isEmpty) {
                      breatheValue = '20';
                    } else {
                      num temp = NumUtil.getNumByValueStr(breatheValue)??0;
                      temp++;
                      breatheValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('血糖(早餐前)', bloodSugarBeforeBreakfastValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue: NumUtil.getNumByValueStr(
                        bloodSugarBeforeBreakfastValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarBeforeBreakfastValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarBeforeBreakfastValue.isEmpty) {
                      bloodSugarBeforeBreakfastValue = '5';
                    } else {
                      num temp = NumUtil.getNumByValueStr(
                          bloodSugarBeforeBreakfastValue)??0;
                      temp--;
                      bloodSugarBeforeBreakfastValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarBeforeBreakfastValue.isEmpty) {
                      bloodSugarBeforeBreakfastValue = '5';
                    } else {
                      num temp = NumUtil.getNumByValueStr(
                          bloodSugarBeforeBreakfastValue)??0;
                      temp++;
                      bloodSugarBeforeBreakfastValue = temp.toString();
                    }
                  });
                }),
                cellItem('血糖(早餐后)', bloodSugarLastBreakfastValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue:
                        NumUtil.getNumByValueStr(bloodSugarLastBreakfastValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarLastBreakfastValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarLastBreakfastValue.isEmpty) {
                      bloodSugarLastBreakfastValue = '5';
                    } else {
                      num temp = NumUtil.getNumByValueStr(
                          bloodSugarLastBreakfastValue)??0;
                      temp--;
                      bloodSugarLastBreakfastValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarLastBreakfastValue.isEmpty) {
                      bloodSugarLastBreakfastValue = '5';
                    } else {
                      num temp = NumUtil.getNumByValueStr(
                          bloodSugarLastBreakfastValue)??0;
                      temp++;
                      bloodSugarLastBreakfastValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('血糖(午餐前)', bloodSugarBeforeLunchValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue:
                        NumUtil.getNumByValueStr(bloodSugarBeforeLunchValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarBeforeLunchValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarBeforeLunchValue.isEmpty) {
                      bloodSugarBeforeLunchValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarBeforeLunchValue)??0;
                      temp--;
                      bloodSugarBeforeLunchValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarBeforeLunchValue.isEmpty) {
                      bloodSugarBeforeLunchValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarBeforeLunchValue)??0;
                      temp++;
                      bloodSugarBeforeLunchValue = temp.toString();
                    }
                  });
                }),
                cellItem('血糖(午餐后)', bloodSugarLastLunchValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue:
                        NumUtil.getNumByValueStr(bloodSugarLastLunchValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarLastLunchValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarLastLunchValue.isEmpty) {
                      bloodSugarLastLunchValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarLastLunchValue)??0;
                      temp--;
                      bloodSugarLastLunchValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarLastLunchValue.isEmpty) {
                      bloodSugarLastLunchValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarLastLunchValue)??0;
                      temp++;
                      bloodSugarLastLunchValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('血糖(晚餐前)', bloodSugarBeforeDinnerValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue:
                        NumUtil.getNumByValueStr(bloodSugarBeforeDinnerValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarBeforeDinnerValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarBeforeDinnerValue.isEmpty) {
                      bloodSugarBeforeDinnerValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarBeforeDinnerValue)??0;
                      temp--;
                      bloodSugarBeforeDinnerValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarBeforeDinnerValue.isEmpty) {
                      bloodSugarBeforeDinnerValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarBeforeDinnerValue)??0;
                      temp++;
                      bloodSugarBeforeDinnerValue = temp.toString();
                    }
                  });
                }),
                cellItem('血糖(晚餐后)', bloodSugarLastDinnerValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue:
                        NumUtil.getNumByValueStr(bloodSugarLastDinnerValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarLastDinnerValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarLastDinnerValue.isEmpty) {
                      bloodSugarLastDinnerValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarLastDinnerValue)??0;
                      temp--;
                      bloodSugarLastDinnerValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarLastDinnerValue.isEmpty) {
                      bloodSugarLastDinnerValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarLastDinnerValue)??0;
                      temp++;
                      bloodSugarLastDinnerValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Row(
              children: <Widget>[
                cellItem('血糖(睡前)', bloodSugarBeforeSleepValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue:
                        NumUtil.getNumByValueStr(bloodSugarBeforeSleepValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarBeforeSleepValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarBeforeSleepValue.isEmpty) {
                      bloodSugarBeforeSleepValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarBeforeSleepValue)??0;
                      temp--;
                      bloodSugarBeforeSleepValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarBeforeSleepValue.isEmpty) {
                      bloodSugarBeforeSleepValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarBeforeSleepValue)??0;
                      temp++;
                      bloodSugarBeforeSleepValue = temp.toString();
                    }
                  });
                }),
                cellItem('血糖(其他)', bloodSugarLastOtherValue, () {
                  _showDiolog(
                    hasPoint: true,
                    currentValue:
                        NumUtil.getNumByValueStr(bloodSugarLastOtherValue)??0,
                    callBack: (value) {
                      setState(() {
                        bloodSugarLastOtherValue = value;
                      });
                    },
                  );
                }, () {
                  setState(() {
                    if (bloodSugarLastOtherValue.isEmpty) {
                      bloodSugarLastOtherValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarLastOtherValue)??0;
                      temp--;
                      bloodSugarLastOtherValue =
                          temp <= 0 ? '0' : temp.toString();
                    }
                  });
                }, () {
                  setState(() {
                    if (bloodSugarLastOtherValue.isEmpty) {
                      bloodSugarLastOtherValue = '5';
                    } else {
                      num temp =
                          NumUtil.getNumByValueStr(bloodSugarLastOtherValue)??0;
                      temp++;
                      bloodSugarLastOtherValue = temp.toString();
                    }
                  });
                }),
              ],
            ),
            Container(
              padding: EdgeInsets.all(20),
              color: Colors.white,
              alignment: Alignment.topLeft,
              height: 200,
              child: TextField(
                controller: textFieldEditer,
                maxLines: 10,
                maxLength: 300,
                autofocus: false,
                focusNode: textFocusNode,
                decoration: InputDecoration(
                  hintText: "请输入备注内容",
                  hintMaxLines: 20,
                  fillColor: Colours.bg_color,
                  filled: true,
                  border: InputBorder.none,
                ),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Expanded(
                  child: Container(),
                  flex: 1,
                ),
                FlatsButton(
                  color: Colours.bg_gray,
                  child: Text(
                    '重置',
                    style: TextStyles.textGray14,
                  ),
                  onPressed: () {
                    _showCupertinoAlertDialog(context);
                  },
                ),
                SizedBox(
                  width: 20,
                ),
                FlatsButton(
                  color: Colours.app_main,
                  child: Text(
                    '提交',
                    style: TextStyle(color: Colors.white, fontSize: 16),
                  ),
                  onPressed: _send,
                ),
                SizedBox(
                  width: 20,
                ),
              ],
            ),
            SizedBox(
              height: 40,
            ),
          ],
        ),
      ),
    ));
  }

  Widget topButtonItem(
      {String? elderTitle,
      String? elderContent,
      String? timeTitle,
      String? timeContent}) {
    return Container(
      width: ScreenUtil.getScreenW(context),
      child: Row(
        children: <Widget>[
          Container(
            width: ScreenUtil.getScreenW(context) / 2,
            padding: EdgeInsets.fromLTRB(20, 20, 20, 10),
            child: Row(
              children: <Widget>[
                Text(elderTitle??"", style: TextStyles.textDark16),
                SizedBox(
                  width: 10,
                ),
                Container(
                  color: Colours.bg_color,
                  height: 40,
                  // padding: EdgeInsets.only(right: 10),
                  child: InkWell(
                    onTap: () {
                      textFocusNode.unfocus();
                      b.Go().push(SelectOldPage((old) {
                        b.Go().pop();
                        setState(() {
                          elderInfo = ElderInfo.fromJson(old.toMap());
                          elderName = old.name??"";
                        });
                      }));
                      // AppNavigator.push(
                      //     context,
                      //     ElderContentPage(
                      //       type: 0,
                      //       isSelected: true,
                      //       cellClickBlocks: (info) {
                      //         setState(() {
                      //           elderInfo = info;
                      //           elderName = info.name;
                      //         });
                      //       },
                      //     ));
                    },
                    child: Row(
                      children: <Widget>[
                        Expanded(
                          flex: 1,
                          child: Text(
                            elderContent??"",
                            textAlign: TextAlign.center,
                            style: TextStyles.textGray16,
                          ),
                        ),
                        Icon(
                          Icons.arrow_drop_down,
                          color: Colours.text_gray,
                        )
                      ],
                    ),
                  ),
                ).setWeight(1)
              ],
            ),
          ),
          Container(
            width: ScreenUtil.getScreenW(context) / 2,
            padding: EdgeInsets.fromLTRB(20, 20, 20, 10),
            child: Row(
              children: <Widget>[
                Text(timeTitle??"", style: TextStyles.textDark16),
                SizedBox(
                  width: 10,
                ),
                Container(
                  color: Colours.bg_color,
                  height: 40,
                  // padding: EdgeInsets.only(right: 10),
                  child: InkWell(
                    onTap: _showTimePicker,
                    child: Row(
                      children: <Widget>[
                        Expanded(
                          flex: 1,
                          child: Text(
                            timeContent??"",
                            textAlign: TextAlign.center,
                            style: TextStyles.textGray16,
                          ),
                        ),
                        Icon(
                          Icons.arrow_drop_down,
                          color: Colours.text_gray,
                        )
                      ],
                    ),
                  ),
                ).setWeight(1)
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget cellItem(String title, String value, Function() sliderMethod,
      Function() reduceMethod, Function() addMethod) {
    return Container(
      color: Colors.white,
      width: ScreenUtil.getScreenW(context) / 2,
      padding: EdgeInsets.fromLTRB(20, 20, 20, 10),
      height: 60,
      alignment: Alignment.center,
      child: Row(
        children: <Widget>[
          Container(
            width: 100,
            alignment: Alignment.center,
            color: Colours.bg_color,
            child: Text(title, style: TextStyles.textDark16),
          ),
          SizedBox(
            width: 10,
          ),
          InkWell(
            child: LoadAssetImage('default/jian'),
            onTap: reduceMethod,
          ),
          Expanded(
            flex: 1,
            child: GestureDetector(
              onTap: sliderMethod,
              // () {
              //   Toast.show('msg');

              // },
              child: Text(
                '$value',
                style: TextStyles.textGray16,
                textAlign: TextAlign.center,
              ),
            ),
          ),
          InkWell(
            child: LoadAssetImage('default/jia'),
            onTap: addMethod,
          ),
        ],
      ),
    );
  }

  //调起时间选择器
  _showTimePicker() {
    DatePicker.showDatePicker(
      context,
      minDateTime: DateTime.parse("1900-01-01 00:00"),
      maxDateTime: DateTime.now(),
      initialDateTime: _selectedDate,
      dateFormat: "yyyy-MM-dd HH:mm",
      locale: DateTimePickerLocale.zh_cn,
      pickerTheme: DateTimePickerTheme(
        showTitle: true,
        confirm: Text('确定'),
      ),
      pickerMode: DateTimePickerMode.datetime, // show TimePicker
      onConfirm: (dateTime, List<int> index) {
        setState(() {
          print(dateTime);
          if (dateTime == null) {
            return;
          }
          this._selectedDate = dateTime;
          time = DateUtil.formatDate(dateTime, format: 'yyyy-MM-dd HH:mm');
          print(time);
        });
      },
    );
  }

  void _showCupertinoAlertDialog(BuildContext cxt) {
    showCupertinoDialog<int>(
        context: cxt,
        builder: (cxt) {
          return CupertinoAlertDialog(
            title: Text('提示'),
            content: Text('是否要重置数据？'),
            actions: <Widget>[
              CupertinoDialogAction(
                child: Text("确定"),
                onPressed: _reset,
              ),
              CupertinoDialogAction(
                child: Text("取消"),
                onPressed: () {
                  Navigator.pop(context);
                },
              ),
            ],
          );
        });
  }

  _showDiolog(
      {bool hasPoint = false, num currentValue = 0,required  Function(String) callBack}) {
    print('$currentValue');
    if (currentValue == null) dialogController.clear();
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return StatefulBuilder(
          builder: (context1, bottomSheetState) {
            return BaseDialog(
              title: "滑动取值",
              width: ScreenUtil.getScreenW(context) - 100,
              child: Container(
                width: double.infinity,
                height: 300,
                color: Colors.white,
                child: Column(
                  children: <Widget>[
                    Container(
                      padding: EdgeInsets.fromLTRB(100, 50, 100, 50),
                      child: TextField(
                        keyboardType: TextInputType.number,
                        controller: dialogController,
                        maxLines: 1,
                        autofocus: false,
                        focusNode: dialogFocusNode,
                        textAlign: TextAlign.center,
                        onEditingComplete: () {
                          // print('🍎');
                          // print('🍎 - ${dialogController.text}');
                          dialogFocusNode.unfocus();
                          bottomSheetState(() {
                            currentValue = NumUtil.getDoubleByValueStr(
                                dialogController.text)??0;
                          });
                        },
                        decoration: InputDecoration(
                          fillColor: Colours.bg_color,
                          filled: true,
                          border: InputBorder.none,
                        ),
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.only(top: 40),
                      child: Slider(
                        value: currentValue.toDouble(),
                        onChanged: (data) {
                          print('change:$data');
                          bottomSheetState(() {
                            currentValue = data;
                            this.dialogController.text =
                                '${NumUtil.getNumByValueDouble(data, 1)}';
                          });
                        },
                        min: 0,
                        max: 300,
                        divisions: 3000,
                        label:
                            '${NumUtil.getNumByValueDouble(currentValue.toDouble(), 1)}',
                        activeColor: Colors.green,
                        inactiveColor: Colors.grey,
                      ),
                    ),
                  ],
                ),
              ),
              onPressed: () {
                dialogFocusNode.unfocus();
                callBack(dialogController.text);
                Navigator.pop(context);
                // UserManager.instance.logout();
                // NavigatorUtils.push(context, LoginRouter.loginPage,
                //     clearStack: true);
              },
            );
          },
        );
      },
    );
    //   showDialog(
    //     context: context,
    //     barrierDismissible: false,
    //     builder: (_) => BaseDialog(
    //       title: "滑动取值",
    //       width: ScreenUtil.getScreenW(context) - 100,
    //       child: Container(
    //         width: double.infinity,
    //         height: 300,
    //         color: Colors.white,
    //         child: Center(
    //           child: Slider(
    //             value: testValue,
    //             onChanged: (data) {
    //               print('change:$data');
    //               setState(() {
    //                 this.testValue = data;
    //               });
    //             },
    //             onChangeStart: (data) {
    //               print('start:$data');
    //             },
    //             onChangeEnd: (data) {
    //               print('end:$data');
    //             },
    //             min: 0.0,
    //             max: 200.0,
    //             divisions: 10,
    //             label: '$testValue',
    //             activeColor: Colors.green,
    //             inactiveColor: Colors.grey,
    //             semanticFormatterCallback: (double newValue) {
    //               return '${newValue.round()} dollars}';
    //             },
    //           ),
    //         ),
    //       ),
    //       onPressed: () {
    //         // UserManager.instance.logout();
    //         // NavigatorUtils.push(context, LoginRouter.loginPage,
    //         //     clearStack: true);
    //       },
    //     ),
    //   );
  }

  @override
  void initState() {
    if(widget.info!=null){
      setState(() {
        elderInfo = widget.info;
        elderName = elderInfo?.name??"";
      });
    }

    super.initState();

  }
}
